﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HR_ParticleEditor
{
    class Particle
    {

        float m_fVelX;

        public float FVelX
        {
            get { return m_fVelX; }
            set { m_fVelX = value; }
        }
        float m_fVelY;

        public float FVelY
        {
            get { return m_fVelY; }
            set { m_fVelY = value; }
        }

        float m_fPosX;

        public float FPosX
        {
            get { return m_fPosX; }
            set { m_fPosX = value; }
        }
        float m_fPosY;

        public float FPosY
        {
            get { return m_fPosY; }
            set { m_fPosY = value; }
        }

        int m_nColorA;

        public int NColorA
        {
            get { return m_nColorA; }
            set { m_nColorA = value; }
        }
        int m_nColorR;

        public int NColorR
        {
            get { return m_nColorR; }
            set { m_nColorR = value; }
        }
        int m_nColorG;

        public int NColorG
        {
            get { return m_nColorG; }
            set { m_nColorG = value; }
        }
        int m_nColorB;

        public int NColorB
        {
            get { return m_nColorB; }
            set { m_nColorB = value; }
        }

        float m_fLife;

        public float FLife
        {
            get { return m_fLife; }
            set { m_fLife = value; }
        }
        float m_fCurrentLife;

        public float FCurrentLife
        {
            get { return m_fCurrentLife; }
            set { m_fCurrentLife = value; }
        }

        float m_fScale;

        public float FScale
        {
            get { return m_fScale; }
            set { m_fScale = value; }
        }

        float m_fRotation;

        public float FRotation
        {
            get { return m_fRotation; }
            set { m_fRotation = value; }
        }

        Form1 ParentEmitter;

        public Form1 ParentEmitter1
        {
            get { return ParentEmitter; }
            set { ParentEmitter = value; }
        }

        public void Update(float fElapsedTime)
        {
            m_fCurrentLife -= fElapsedTime;
            //float change = m_fLife - m_fCurrentLife * 100;
            m_nColorA += (int)(((ParentEmitter.NEndAlpha - ParentEmitter.NStartAlpha)) * fElapsedTime);
            if (m_nColorA < 0)
                m_nColorA = 0;
            m_nColorR += (int)(((ParentEmitter.NEndR - ParentEmitter.NStartR)) * fElapsedTime);
            if (m_nColorR < 0)
                m_nColorR = 0;
            m_nColorG += (int)(((ParentEmitter.NEndG - ParentEmitter.NStartG)) * fElapsedTime);
            if (m_nColorG < 0)
                m_nColorG = 0;
            m_nColorB += (int)(((ParentEmitter.NEndB - ParentEmitter.NStartB)) * fElapsedTime);
            if (m_nColorB < 0)
                m_nColorB = 0;
            m_fVelX += ((ParentEmitter.FEndVelX - ParentEmitter.FStartVelX) / m_fCurrentLife) * fElapsedTime;
            m_fVelY += ((ParentEmitter.FEndVelY - ParentEmitter.FStartVelY) / m_fCurrentLife) * fElapsedTime;
            m_fPosX = FPosX + (FVelX * fElapsedTime);
            m_fPosY = FPosY + (FVelY * fElapsedTime);
            m_fRotation += ((ParentEmitter.FEndRotation - ParentEmitter.FStartRotation) / m_fCurrentLife) * fElapsedTime;
            m_fScale += ((ParentEmitter.FEndScale - ParentEmitter.FStartScale) / m_fCurrentLife) * fElapsedTime;
        }


        public void Renew()
        {
            m_nColorA = ParentEmitter.NStartAlpha;
            m_nColorR = ParentEmitter.NStartR;
            m_nColorG = ParentEmitter.NStartG;
            m_nColorB = ParentEmitter.NStartB;
            m_fPosX = ParentEmitter.rnd.Next((int)ParentEmitter.FPosX) + 1;
            m_fPosY = ParentEmitter.rnd.Next((int)ParentEmitter.FPosY) + 1;

            m_fLife = ParentEmitter.rnd.Next((int)ParentEmitter.FCurrLife) + 1;
            m_fCurrentLife = m_fLife;
            m_fRotation = ParentEmitter.FStartRotation;
            m_fScale = ParentEmitter.FStartScale;
            m_fVelX = ParentEmitter.FStartVelX;
            int NegX = ParentEmitter.rnd.Next(3) - 1;
            if (NegX == -1)
                m_fVelX = -m_fVelX;
            m_fVelY = ParentEmitter.FStartVelY;
             int NegY = ParentEmitter.rnd.Next(3) - 1;
             if (NegY == -1)
                 m_fVelY = -m_fVelY;
        }
    }

}
